package com.tianqu.tms.www.transfer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.transfer.actionform.TransferRgActionForm;
import com.tianqu.tms.www.transfer.viewhelper.TransferRgInputViewHelper;

public class PTransactionsInputDispatchAction extends TmsAction {
	private Logger logger = Logger.getLogger(PTransactionsInputDispatchAction.class);

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TransferRgActionForm inputForm = (TransferRgActionForm) form;
		TransferRgInputViewHelper view = (TransferRgInputViewHelper) uc.getAttribute(TmsConstants.VIEWHELP);
		if(view!=null){
			view.setCardType(inputForm.getCardType());
			view.setCarType(inputForm.getCarType());
			view.setCarUse(inputForm.getCarUse());
			view.setCarMarketIn(inputForm.getCarMarketIn());
			view.setCheckUserId(inputForm.getCheckUserId());
			view.setOwnerType(inputForm.getOwnerType());
			view.setOwnerType(inputForm.getOwnerType());
			view.setChangeBody(inputForm.getChangeBody());
			if(StringUtils.isNumeric(inputForm.getChangeTradeTicket())) view.setChangeTradeTicket(Integer.parseInt(inputForm.getChangeTradeTicket()));
			view.setSerial(inputForm.getSerial());
			view.setVin(inputForm.getVin());
			view.setLicensePlate(inputForm.getLicensePlate());
			view.setRegisterCardNo(inputForm.getRegisterCardNo());
			view.setTransNo(inputForm.getTransNo());
			view.setPrice(inputForm.getPrice());
			view.setIdentification(inputForm.getIdentification());
			view.setCarOwner(inputForm.getCarOwner());
			view.setOwnerPhone(inputForm.getOwnerPhone());
			view.setOwnerAddress(inputForm.getOwnerAddress());
			view.setNewIdentification(inputForm.getNewIdentification());
			view.setNewCarOwner(inputForm.getNewCarOwner());
			view.setNewOwnerPhone(inputForm.getNewOwnerPhone());
			view.setNewOwnerAddress(inputForm.getNewOwnerAddress());
			uc.setAttribute(TmsConstants.VIEWHELP, view);
		}
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
